package com.quanshu.shop.main.adapter;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.bumptech.glide.Glide;
import com.quanshu.exchange.R;
import com.quanshu.exchange.support.config.Config;
import com.quanshu.shop.base.tool.BaseTool;
import com.quanshu.shop.goods.view.GoodsWebviewActivity;
import com.quanshu.shop.main.entity.ShopMainEntity;

import java.util.List;

/**
 * 作者  李哲
 * 创建时间 2018/7/18
 * 邮箱 lizhetongliao@163.com
 * 说明
 **/
public class Special1Adapter extends DelegateAdapter.Adapter<Special1Adapter.Special1AdapterViewHolder> {
    private Context mContext;
    private List<ShopMainEntity.SpecialEntity> specialEntityList;
    private LayoutHelper layoutHelper;
    public static final int SPECIAL1_TYPE = 5;

    public Special1Adapter(Context mContext, List<ShopMainEntity.SpecialEntity> specialEntityList, LayoutHelper layoutHelper) {
        this.mContext = mContext;
        this.specialEntityList = specialEntityList;
        this.layoutHelper = layoutHelper;
    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return layoutHelper;
    }

    @NonNull
    @Override
    public Special1Adapter.Special1AdapterViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if (viewType == SPECIAL1_TYPE) {
            return new Special1Adapter.Special1AdapterViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_shop_special1_goods, parent, false));
        }
        return null;

    }

    @Override
    public void onBindViewHolder(@NonNull Special1AdapterViewHolder holder, int position) {
        Glide.with(mContext).load(Config.URL_HOST_SHOP + specialEntityList.get(position).getMob_headpic()).into(holder.imageView);
        holder.textView1.setText(specialEntityList.get(position).getSpecial_name());
        if (position == 0) {
            holder.textView2.setText("品质保证");
            holder.view.setVisibility(View.VISIBLE);
        } else {
            holder.textView2.setText("中华瑰宝");
            holder.view.setVisibility(View.GONE);
        }
        holder.linearLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle=new Bundle();
                bundle.putString(GoodsWebviewActivity.GOODS_WEBVIEW_URL,specialEntityList.get(position).getMob_link());
                BaseTool.goActivity(mContext, GoodsWebviewActivity.class,bundle);
            }
        });

    }

    @Override
    public int getItemViewType(int position) {
        return SPECIAL1_TYPE;
    }

    @Override
    public int getItemCount() {
        return specialEntityList != null ? 2 : 0;
    }

    class Special1AdapterViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        TextView textView1;
        TextView textView2;
        View view;
        LinearLayout linearLayout;

        public Special1AdapterViewHolder(View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.shop_main_special_img);
            textView1 = itemView.findViewById(R.id.shop_main_special_txt);
            textView2 = itemView.findViewById(R.id.shop_main_special_txt1);
            view = itemView.findViewById(R.id.shop_main_special_line);
            linearLayout = itemView.findViewById(R.id.specil2);
        }
    }
}
